<template>
    <div class="header-wrap" :class="store.theme">
        <div class="header-left">
            <Hamburger></Hamburger>
            <Breadcrumb></Breadcrumb>
        </div>
        <div class="header-right">
            <div class="btn-groups">
                <div class="btn">
                    <el-tooltip effect="dark" :content="isDark ? '切换亮色模式' : '切换深色模式'" placement="bottom">
                        <el-switch v-model="isDark" @change="toggleDark" inline-prompt inactive-icon="Sunny"
                            active-icon="Moon" />
                    </el-tooltip>
                </div>
                <div class="btn" @click="fullScreenHandle">
                    <el-tooltip effect="dark" :content="!isFullscreen ? '全屏' : '退出全屏'" placement="bottom">
                        <el-icon color="#666">
                            <FullScreen />
                        </el-icon>
                    </el-tooltip>
                </div>
            </div>
        </div>
    </div>
</template>

<script setup>
import Hamburger from './hamburger.vue'
import Breadcrumb from './breadcrumb.vue'
import screenfull from 'screenfull'
import { ref, watch } from "vue";
import { useWebStore } from "../../store/webStore";
import { useDark, useToggle } from "@vueuse/core";


const switchTheme = useDark()

const toggleDark = useToggle(switchTheme)

const store = useWebStore()

const isDark = ref(store.theme === 'dark' ? true : false)

const isFullscreen = ref(false)

watch(isDark, (val) => {
    store.setTheme(val)
})

const fullScreenHandle = () => {
    if (screenfull.isEnabled) {
        screenfull.toggle()
        isFullscreen.value = !screenfull.isFullscreen
    }
}


</script>

<style lang='scss' scoped>
.el-header {
    padding: 0;
}

.header-wrap {
    width: 100%;
    height: 60px;
    overflow: hidden;
    background-color: #fff;
    box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-sizing: border-box;
    position: relative;

    &.dark {
        background-color: #202020;
    }

    .header-left,
    .header-right {
        display: flex;
        align-items: center;

        .btn-groups {
            display: flex;
            align-items: center;
            height: 100%;

            .btn {
                width: 30px;
                height: 30px;
                margin-left: 20px;

                .el-icon {
                    width: 100%;
                    height: 100%;

                    svg {
                        width: inherit;
                        height: inherit;
                    }
                }
            }
        }
    }
}
</style>